 const webpack = require('webpack')
const path = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin')

module.exports = {
    entry: path.join(__dirname, '/src/index.js'),
    output: {
        path: __dirname + '/dist',
        filename: '[name].js'
    },
    module:{
        rules:[{
            test:/\.jsx?$/,
            use: {
                loader: 'babel-loader',
                options: {
                    presets: [
                        "@babel/preset-react", "@babel/preset-env", "mobx"
                    ],
                    plugins: [
                        [
                            "@babel/plugin-proposal-decorators",
                            {
                                "legacy": true
                            }
                        ],
                        ["import", {
                            "libraryName": "antd",
                            "libraryDirectory": "es",
                            "style": "css" // `style: true` 会加载 less 文件
                        }],
                    ]
                }
            },
            exclude: /node_modules/,

        },
        {
            test:/\.css$/,
            use: ['style-loader', 'css-loader'],
            //    exclude: /node_module/,
        },
        {
            test:/\.(scss|css)$/,
            use:[
                "style-loader",
                {
                    loader:'css-loader',
                    options:{url: false, sourceMap: true},
                },
                {
                    loader:'sass-loader',
                    options: {sourceMap: true}
                }
            ],
            exclude: /node_module/
        },
        {
            test: /\.(png|jpg)$/,
            loader: 'url-loader?limit=8192&name=images/[hash:8].[name].[ext]',
            options: {
                publicPath: '/'
            }
        }]
    },
    devtool:"eval-source-map",
    devServer: {
        contentBase: path.join(__dirname, 'dist'),
        port: 3000,
        host: '0.0.0.0',
        proxy: {
            '/remote': {
                target: 'http://127.0.0.1',
                pathRewrite: {
                    '^/remote' : ''
                }
            }

        }
    },
    resolve: {
        // 设置别名
        alias: {
            '@': path.join(__dirname, '/src'),
            'components': path.join(__dirname, '/src/components'),
            'ochart': path.join(__dirname, '/src/ochart'),
            'pages': path.join(__dirname, '/src/pages'),
            'decorate': path.join(__dirname, '/src/decorate'),
            'resolvers': path.join(__dirname, '/src/resolvers'),
            'utils': path.join(__dirname, '/src/utils'),
            'jquery': path.join(__dirname, '/thd/jquery-2.0.0.min'),
            'jquery-ui': path.join(__dirname, '/thd/jquery-ui'),
        }
    },
    plugins: [
        new HtmlWebpackPlugin({
            title: 'Stock Go',
            meta: {
                keywords: 'Stock Go',
                description: '为交易而生'
            },
            inject: true,
            template: path.join(__dirname, '/template.html'),
            filename:'index.html',
            minify: {
                collapseWhitespace: true,
                preserveLineBreaks: true
            }
        }),
      new webpack.ProvidePlugin({
          $: 'jquery',
          jQuery: 'jquery',
      })
    ]
}
